package com.eshop.modules.user.service.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eshop.common.mapper.CoreMapper;
import com.eshop.modules.user.domain.ShopUser;
import com.eshop.modules.user.service.dto.PromUserDto;
import java.math.BigDecimal;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

@Repository
public interface UserMapper extends CoreMapper<ShopUser> {
    @Update({"update eshop_user set integral=integral-#{integral} where uid=#{uid}"})
    int decIntegral(@Param("integral") double d, @Param("uid") Long l);

    @Update({"update eshop_user set now_money=now_money-#{payPrice} where uid=#{uid}"})
    int decPrice(@Param("payPrice") BigDecimal bigDecimal, @Param("uid") Long l);

    @Select({"<script>SELECT u.uid,u.nickname,u.avatar,DATE_FORMAT(u.create_time,'%Y/%m/%d') as time,u.spread_count as childCount,COUNT(o.id) as orderCount,IFNULL(SUM(o.pay_price),0) as numberCount FROM eshop_user u LEFT JOIN store_order o ON u.uid=o.uid WHERE u.uid in <foreach item='id' index='index' collection='uids'  open='(' separator=',' close=')'>   #{id} </foreach> <if test='keyword != null'> AND ( u.nickname LIKE CONCAT(CONCAT('%',#{keyword}),'%') OR u.phone LIKE CONCAT(CONCAT('%',#{keyword}),'%'))</if> GROUP BY u.uid ORDER BY #{orderByStr} </script>"})
    List<PromUserDto> getUserSpreadCountList(Page page, @Param("uids") List list, @Param("keyword") String str, @Param("orderByStr") String str2);

    @Update({"update eshop_user set brokerage_price = brokerage_price+ ${price} where uid = #{id}"})
    void incBrokeragePrice(@Param("price") BigDecimal bigDecimal, @Param("id") Long l);

    @Update({"update eshop_user set integral=integral+#{integral} where uid=#{uid}"})
    int incIntegral(@Param("integral") double d, @Param("uid") Long l);

    @Update({"update eshop_user set now_money=now_money+#{price} where uid=#{uid}"})
    int incMoney(@Param("uid") Long l, BigDecimal bigDecimal);

    @Update({"update eshop_user set pay_count=pay_count+1 where uid=#{uid}"})
    int incPayCount(@Param("uid") Long l);

    @Update({"update eshop_user set now_money = now_money + ${money} where uid = #{id}"})
    void updateMoney(@Param("money") double d, @Param("id") long j);

    @Update({"update eshop_user set status = #{status} where uid = #{id}"})
    void updateOnstatus(@Param("status") Integer num, @Param("id") Long l);
}
